//        https://ac.nowcoder.com/acm/contest/11194/A




#include<iostream>
using namespace std;
int a[600008], b[600008];
int main()
{
    int n;
    string s;
    cin >> n >> s;
    s += s;
    for (int i = 1; i <= 2 * n; i++)
    {
        if (s[i - 1] == '1')
            a[i]++;
        else
            b[i]++;
        a[i] += a[i - 1];
        b[i] += b[i - 1];
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (a[i + n / 2 - 1] - a[i - 1] == a[n] / 2 && b[i + n / 2 - 1] - b[i - 1] == b[n] / 2)
            ans++;
    }
    cout << ans << endl;
    return 0;
}